<?php


namespace app\common\service\order\coupon_order\jutuike_channel;

use app\model\CouponOrder;
use think\facade\Db;

/**
 * 权益接口
 * Class Vip
 * @package app\common\service\order\coupon_order\jutuike_channel
 */
class Vip extends JutuikeChannelBase
{

    public function getServType()
    {
        return PRODUCT_COUPON_SERV;
    }

    /**
     * @return CouponOrder|bool|mixed
     */
    public function syncOrder()
    {
        if (!in_array($this->params['status'], [1, 2, 3])) {
            return false;
        }
        //状态允许的时候再保存数据
        /**
         * @var CouponOrder $couponOrder
         */
        $couponOrder = $this->saveOrder();

        if ($this->params['status'] == 3 && $couponOrder->agent_settle_status == CouponOrder::C_AGENT_SETTLE_STATUS_NO){
            $couponOrder->log.=date('Y-m-d H:i:s').'修改为待结算vip';
            $couponOrder->agent_settle_status = CouponOrder::C_AGENT_SETTLE_STATUS_WAIT;
            $couponOrder->save();
        }
        return $couponOrder;

    }



    public function getProductName()
    {
        return $this->params['order_title'] ??'';
    }

    public function getProductImage()
    {
        return $this->params['icon']??'';
    }

    /**
     * 获取原价 比如 qq会员30块，原销售价 有得话加，没有就算了
     */
    public function getOriginAmount(){

        $originAmount = Db::name('coupon_product_channel')
            ->where('supplier_id', $this->supplier_id)
            ->where('name', $this->product_name)
            ->value('market_price', 0);

        return $originAmount;

    }

    /**
     * 代理结算状态
     */
    public function getAgentSettleStatus(){
        //聚推客
        return $this->params['status'] == 3 ? CouponOrder::C_AGENT_SETTLE_STATUS_WAIT : CouponOrder::C_AGENT_SETTLE_STATUS_NO;
    }

    public function getStatus(){
        //拉取的都是充值成功的
        return CouponOrder::C_STATUS_RECHARGE_SUCCESS;
    }


}